<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>家长关联</title>
	<meta name="decorator" content="default"/>
	<%@ include file="/WEB-INF/views/include/dialog.jsp"%>
	<script src="${ctxStatic}/front/js/myValidate.js"></script> 
	<script type="text/javascript">
		$(document).ready(function() {
			$("#inputForm").validate({
				rules : {
					parentName : {
						required : true
					},
					relationship : {
						required : true
					}
				},
				messages : {
					parentName : {
						required: "请进行家长选择"
					},
					relationship : {
						required: "请选择"
					}
				},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		$(document).ready(function() {
			$("#f_bind").validate({
				rules : {
					idCard : {
						required : true,
						isIdcard:true
					},
					relationship: {
						required : true
					}
				},
				messages : {
					idCard : {
						required: "请选择",
						minlength : '身份证号长度不能小于18位',
						maxlength : '身份证号长度不能大于18位'
					},
					relationship: {
						required: "请选择"
					}
				},
			/* 	submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				}, */
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function openDialog(){
			$("#idCard").val("");
			$("#dialog").dialog({
			bgiframe: true,
	        resizable: true, //是否可以重置大小
	        height: 200, //高度
	        width: 400, //宽度
	        draggable: false, //是否可以拖动。
	        title: "家长获取",
	        modal: true,
	        show : {
				effect : 'drop',
				direction : 'up'
			}
			});
		};
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<%-- <li><a href="${ctx}/dd/ddParentRelationship/">关联列表</a></li>
		<li class="active"><a
			href="${ctx}/dd/ddParentRelationship/form?id=${ddParentRelationship.id}"><shiro:hasPermission
					name="dd:ddParentRelationship:edit">${not empty ddParentRelationship.id?'关联修改':'家长绑定'}</shiro:hasPermission>
				<shiro:lacksPermission name="dd:ddParentRelationship:edit">查看</shiro:lacksPermission></a></li> --%>
	</ul>
	<br/>
	<form:form id="inputForm" modelAttribute="ddParentRelationship" action="${ctx}/dd/ddParentRelationship/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="studentId"/>
		<form:hidden path="parentId"/>
		<sys:message content="${message}"/>	
		
		
		<div class="control-group">
			<label class="control-label">学生：</label>
			<div class="controls">
			<span>${fns:getStudentName(ddParentRelationship.studentId)}</span>&nbsp;&nbsp;
			<input onclick="openDialog();" class="btn btn-small" type="button" value="获取家长" style="color:green;"/>
			</div>
		</div>
			
		<div class="control-group">
			<label class="control-label">家长：</label>
			<div class="controls">
			<form:input path="parentName" htmlEscape="false" maxlength="50" class="input-xlarge " required="required" readonly="true"/>
			</div>
		</div>
		
		
		<div class="control-group">
			<label class="control-label">关系：</label>
			<div class="controls">
			  <form:select path="relationship" class="input-mini form-control required ">
			                    <form:option value="">请选择</form:option>		
								<form:options items="${fns:getDictList('relationship')}" itemLabel="label"
								itemValue="value" htmlEscape="false" class="" />
							</form:select> 
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:input path="remark" htmlEscape="false" maxlength="2000" class="input-xlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="dd:ddParentRelationship:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<!-- <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/> -->
		</div>
	</form:form>
	
	<div style="display:none;overflow:hidden;padding:3px" id="dialog">
		<form class="form-horizontal" role="form" id="f_bind"
			action="" method="post">
			<div class="clearfix" style="height: 20px"></div>
			<div class="control-group">
				<label class="control-label"><b
					style="color: red; font-size: large">*</b>家长身份证:</label> &nbsp; <input
					class="input-medium" id="idCard" name="idCard" placeholder="请输入" required="required"
					 min="0" />
					<label class="control-label" id="tip" style="color:red;"></label>
			</div>
					
			<div class="clearfix" style="height: 10px"></div>
			<div class="control-group" style="width: 15%; margin:auto;">
				<input type=button id="bindSubmit" class="" value="提交" />
			</div>
		</form>
	</div>
	<script>
		$(function() {
			$('#bindSubmit').click(function() {//点击按钮提交
				$.ajax({
					url : "${ctx}/ajax/get/parent.do",
					data : $("#f_bind").serialize(),
					type : "post",
					success : function(data) {//ajax返回的数据
						var json=eval("("+data+")");
						if (!json && typeof json != "undefined" && json != 0) {
							//空，就是家长不存在的时候
							//$("#idCard").val("");
							$("#tip").html("家长不存在");
						} else {
							$("#dialog").dialog('close');
							$("#parentName").val(json.name);
							$("#parentId").val(json.id);
						}
					},
					error : function(data) {//ajax返回的数据
						var json=eval("("+data+")");
						alert(json);
						$("#dialog").dialog('close');
					}
				});
			});

		});
	</script>
</body>
</html>